﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OracleClient;
public partial class changyong_zaishou : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    public void BindData()
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        string sqlstr = "select * from booksale.Book_Condi order by 编号";
        OracleConnection con = new OracleConnection(connet);
        OracleDataAdapter da = new OracleDataAdapter(sqlstr, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        G1.DataSource = ds;
        G1.DataKeyNames = new string[] { "编号" };
        G1.DataBind();


    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        string sqlstr = "select * from booksale.Book_Condi where 编号='" + bookid.Text + "' or 名称='" + bookname.Text + "'";
        OracleConnection con = new OracleConnection(connet);
        OracleDataAdapter da = new OracleDataAdapter(sqlstr, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        G1.DataSource = ds;
        G1.DataKeyNames = new string[] { "编号" };
        G1.DataBind();
    }
    protected void G1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        G1.PageIndex = e.NewPageIndex;
        BindData();
    }
    protected void G1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        G1.EditIndex = e.NewEditIndex;
        BindData();
    }
    protected void G1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string num = G1.DataKeys[e.RowIndex].Value.ToString();
     
        string author = ((TextBox)(G1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
        string update = "update booksale.Book_Condi set 状态='" + author + "' where 编号='" + num + "'";
        bool i = ConnectSQL(update);
        if (i)
        {
            Response.Write("<script language=javascript>alert('修改成功')</script");
            G1.EditIndex = -1;
            BindData();
        }
        else { Response.Write("<script language=javascript>alert('修改失败')</script"); }

    }
    public bool ConnectSQL(string strSqlCom)
    {
        string connet = "Data Source=orcl;User ID=booksale;Password=Qwertyuiop1;Unicode=True";
        OracleConnection con = new OracleConnection(connet);
        OracleCommand com = new OracleCommand(strSqlCom, con);
        try
        {
            if (con.State == System.Data.ConnectionState.Closed)
            { con.Open(); }
            com.ExecuteNonQuery();
            return true;


        }
        catch
        { return false; }
        finally
        { con.Close(); }
    }

    protected void G1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        G1.EditIndex = -1;
        BindData();
    }
}